using System;

namespace SharpMud.Server.Systems.Security.Entities.BuiltIn.Users
{
	public class Anonymous : SharpMud.Server.Systems.Security.Entities.IUser
	{
		private const string	_UserName	=	"";
		private const string	__UserID 	=	"{00000000-0000-0000-0000-000000000000}";

		#region Private Variables
		
		private SecurityManager _SecurityManager;
		private Guid		_UserID;
		private string			_UnhashedPassword;
		private string			_HashedPassword;
		#endregion

		#region Constructors
		public Anonymous()
			:this(SecurityManager.GlobalInstance)
		{
		}
		public Anonymous(SecurityManager securityManager)
		{
			if(securityManager==null)
				throw new InvalidOperationException("There must be an instance of SharpMud.Server.Systems.SecurityManager available to this IUser");
			_SecurityManager = securityManager;
			this._UserID = new Guid(__UserID);
			this._UnhashedPassword = "";
			this._HashedPassword = Security.Utility.DefaultTextEncoding.GetString(
				Security.Utility.DefaultHashAlgorithm.ComputeHash(
				Security.Utility.DefaultTextEncoding.GetBytes(UnhashedPassword)
				) );
		}
		#endregion

		#region IUser Members

		public Guid UserID
		{
			get
			{
				return this._UserID;
			}
		}

		internal string UnhashedPassword
		{
			get
			{
				return this._UnhashedPassword;
			}
		}

		public string HashedPassword
		{
			get
			{
				return this._HashedPassword;
			}
		}

		public IUserRole[] UserRoles
		{
			get
			{
				return null;
			}
		}

		#endregion

		#region IUser Members

		public bool HasPassword(string passwordGuess)
		{
			if(passwordGuess == String.Empty) return true;

			return false;
		}

		public bool IsInRole(string roleName)
		{
			return this.IsInRole(new Entities.UserRoleReference(roleName));
		}

		public bool IsInRole(IUserRole role)
		{
			return this.IsInRole(new Entities.UserRoleReference(role));
		}

		public bool IsInRole(UserRoleReference roleReference)
		{
			// TODO:  Add Anonymous.SharpMud.Server.Systems.Security.Entities.IUser.IsInRole implementation
			return false;
		}

		public UserReference GetReference()
		{
			return new UserReference(this);
		}

		#endregion

		#region IEntity Members

		public string Name
		{
			get
			{
				// TODO:  Add Anonymous.Name getter implementation
				return null;
			}
		}

		public Guid ID
		{
			get
			{
				// TODO:  Add Anonymous.ID getter implementation
				return new Guid ();
			}
		}

		EntityReference SharpMud.Server.Systems.Security.Entities.IEntity.GetReference()
		{
			// TODO:  Add Anonymous.SharpMud.Server.Systems.Security.Entities.IEntity.GetReference implementation
			return null;
		}

		#endregion
	}
}
